package com.leyou.page.controller;

import com.leyou.page.service.PageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.Map;

/**
 * 详情控制器
 */
@Controller
public class PageController {

    @Autowired
    private PageService pageService;

    /**
     * 商品详情请求
     * 路径： /item/100.html
     */
    @GetMapping("/item/{id}.html")
    public String pageDetail(@PathVariable("id") Long id,Model model){
        //1.获取商品详情需要的数据
        Map<String,Object> resultMap = pageService.pageDetail(id);
        //2.把数据传递到页面
        model.addAllAttributes(resultMap);
        return "item";
    }

}
